set cent on
set proc to sospro
set proc to boxproc
DR='N:'
STORE ' ' TO AEANAME,AEAADDR,AEACITY,AEACOUN,AEACURR
STORE .F. TO AEAHEAL,AEADECI
DO START

set function 10 to space(4)
DR='N:'
f2='company'
F21='NMCOMP'
SELE 1
use
set exclu off
use &dr&f2 index &dr&f2,&dr&f21
go bottom
set colo to bg+/b,w+/n
CLEAR
SET COLO TO BG+/B,w+/n
DO ADDRESSS
*@ 5,5 SAY 'C O M P A N Y   E N T R Y   &   U P D A T E'
*@ 4,3 TO 6,49 DOUBLE
DO ADDRTITL WITH 'C O M P A N Y   E N T R Y   &   U P D A T E'
SET COLO TO W+/B,W+/N
set inte off
@ 11,3 say 'CODE           :'
@ 12,3 SAY 'NAME           :'
@ 13,3 say 'ADDRESS :'
@ 15,3 SAY 'CITY           :'
@ 16,3 SAY 'COUNTRY        :'
@ 17,3 say 'TELP 1         :'
@ 18,3 SAY 'PAM CODE       :'
**
** 7/12/99 - Dickson 
@ 21,3 SAY 'VAT TAX CODE   :'
**
@ 20,3 SAY 'FAX & TELEX    :'
@ 20,38 SAY '/'
@ 09,3 SAY 'AEA MEMBERSHIP :'

set color to w
LORG=SAVESCREEN(0,0,24,79)
del_rec = 'N'
option = 0
do while option <> 9
   option = 1
   set deli off
   NOR=RECNO()
   record_no = recno()
   kode     = comp_code
   name     = comp_name
   AEAM     = AEA_MEMBER
   MNUM     = MEMB_NUMB
   CMEM     = MEMB_CODE
   tel1     = comp_tel1
   tel2     = comp_tel2
   tel3     = comp_tel3
   fax      = comp_fax
   telex    = comp_telex
   add1     = comp_add1
   add2     = comp_add2
   city     = comp_city
   negara   = comp_count

   SET COLO TO w+/n
   IF AEAM
      SELE 5
      F5='MSHTYPE'
      SELE 5
      SET EXCLU OFF
      USE &DR&F5
      LOCAT FOR MEMB_CODE=CMEM .AND. .NOT. EOF()
      IF FOUND()
         NMEM=MEMB_NAME
      ELSE
         NMEM=''
      ENDIF

*      SET COLO TO BG+/B,W+/N
*      @ 7,40 CLEAR TO 9,78
*      @ 7,40 SAY ALLTRIM(NMEM)
*      @ 8,40 SAY 'FR : '+DTOC(MDR)+' TO : '+DTOC(MHG)
*      @ 9,40 SAY 'MEMBERSHIP #. : ' +MNUM
*      SET COLO TO W+/N
   ELSE
      SET COLO TO BG+/B,W+/N
      @ 7,40 CLEAR TO 9,78
      SET COLO TO W+/N
      NMEM=SPACE(30)
   ENDIF
   SELE 1

   SET COLO TO GR+/B,w+/B

   @ 11,20 say kode
   @ 12,20 say name
   @ 13,13 say add1
   @ 14,13 say add2
   @ 15,20 say city
   @ 16,20 say negara
   @ 17,20 say tel1
   @ 18,20 say tel2
**
**  7/12/99 - Dickson   - Used TEL3 as VAT Tax code field
**   @ 19,20 say tel3
   @ 21,20 say tel3      
**   
**
   @ 20,20 say fax
   @ 20,41 SAY TELEX
   @ 09,20 SAY AEAM
   IF AEAM
      @ 09,25 SAY NMEM
   ELSE
      SET COLO TO BG+/B,W+/N
      @ 9,25 CLEAR TO 9,78
   ENDIF
   DO MN_FORMM
   do case
      case option = 7
         do while .T.
            kode     = spac(4)
* Extend name store company name from 36 up to 100 chars
* Changed on 25/Mar/2011 by Thien
            name     = spac(100)
* End Thien
            STORE SPACE(16) TO tel1,tel2,tel3,CITY,NEGARA,FAX,TELEX
* Extend add1 & add2 fields from 60 & 40 to 100 chars
* Changed on 7/Apr/2011 by Thien
            add1     = spac(100)
* End Thien
            add2     = spac(40)
            SET COLO TO BG+/B,W+/N
            @ 9,25 CLEAR TO 9,78
            LAY=SAVESCREEN(0,0,24,79)
            @ 09, 29 say "/"
            SET COLO TO GR+/N,W+/N
            @ 09, 25 PROMPT "YES"
            @ 09, 31 PROMPT "NO"
            rest from N:compan addi
            MENU TO CHCOM
            do case
               case CHCOM=1
                  codaea=codaea+1
                  KODE=STR(CODAEA,4)
                  AEAM=.T.
               case CHCOM=2
                  AEAM=.F.
                  NMEM=""
                  CODCLI=CODCLI+1
                  KODE=STR(CODCLI,4)
            ENDCASE

            IF CHCOM=1
               SELE 5
               F5='MSHTYPE'
               SELE 5
               SET EXCLU OFF
               USE &DR&F5
               COUNT TO CNT
               IF CNT=0
                  RESTSCREEN(0,0,24,79,LAY)
                  LOOP
               ENDIF
               DECLARE FILD[CNT]
               DECLARE MCOD[CNT]
               DECLARE DARI[CNT]
               DECLARE HING[CNT]
               DECLARE MNAM[CNT]
               SELE 5
               GO TOP
               CR=0
               DO WHILE .NOT. EOF()
                  CR=CR+1
                  FILD[CR]=MEMB_CODE+' '+MEMB_NAME
                  MNAM[CR]=MEMB_NAME
                  MCOD[CR]=MEMB_CODE
                  DARI[CR]=MEMB_START
                  HING[CR]=MEMB_END
                  SKIP
               ENDDO
               set colo to w/b
               inkey()
               set colo to w+/rb,gr+/r
               @ 17,3 clea to 23,75
               @ 17,3 to 23,75 double
               pilih=achoice(18,5,22,73,FILD)
               IF LASTKEY()=13
                  DARF=FILD[PILIH]
                  CMEM=MCOD[PILIH]
                  NMEM=MNAM[PILIH]
                  MDR=DARI[PILIH]
                  MHG=HING[PILIH]
               else
                  SET COLO TO BG+/B,W+/N
                  RESTSCREEN(0,0,24,79,LAY)
                  LOOP
               ENDIF
             ELSE
               NMEM=SPACE(30)
               CMEM=SPACE(3)
             ENDIF

           SELE 1
            SET COLO TO w+/B,W+/N
            RESTSCREEN(0,0,24,79,LAY)
            @ 09,35 clea to 09,62
            @ 09,20 SAY AEAM
            @ 09,25 SAY NMEM
            @ 11,20 say kode
            @ 12,20 say name
            @ 13,13 say add1
            @ 14,13 say add2
            @ 15,20 say city
            @ 16,20 say negara
            @ 17,20 say tel1
            @ 18,20 say tel2
**            
** 7/12/99 - Dickson
**            @ 19,20 say tel3
            @ 21,20 say tel3                   
**            
**
            @ 20,20 say fax
            @ 20,41 SAY TELEX


            SET INTE ON
            set deli OFF
            if m->kode=space(4)
               exit
            endif
            @ 12,20 GET name PICT '@!'
            @ 13,13 GET add1 PICT '@!'
            @ 14,13 GET add2 PICT '@!'
            @ 15,20 GET city PICT '@!'
            @ 16,20 GET negara PICT '@!'
            @ 17,20 GET tel1 PICT '@!'
            @ 18,20 GET tel2 PICT '@!'
** 7/12/99 - Dickson
**            @ 19,20 GET tel3 PICT '@!'
            @ 21,20 GET tel3 PICT '@!'            
**            
**
            @ 20,20 GET fax  PICT '@!'
            @ 20,41 GET telex PICT '@!'
            read
            LAYAR=SAVESCREEN(0,0,24,79)
            choice = 'Y'
            do get_optn with 'SAVE (Y/N)','YN',choice
            if choice = 'Y'
               SAVE ALL LIKE COD* TO n:COMPAN
               if fil_lock()
                  append blank
               endif
               if rec_lock()
                  repl comp_code  with kode,comp_name  with name,comp_tel1  with tel1
                  repl comp_tel2  with tel2,comp_tel3  with tel3,comp_fax   with fax
                  repl comp_telex with telex,comp_add1  with add1,comp_add2  with add2
                  repl comp_city  with city,comp_count with negara
                  IF CHCOM=1
                     REPL MEMB_CODE  WITH CMEM
                     REPL AEA_MEMBER WITH .T.
                  ENDIF
                  UNLOCK
               endif
               unlock
               NOR=RECNO()
            ELSE
               DO CASE
                  CASE chcom=1
                     codaea=codaea-1
                  CASE Chcom=2
                     codcli=codcli-1
               ENDCASE
               SAVE ALL LIKE CO* TO n:COMPAN
            endif
            anext = 'Y'
            do get_optn with 'ADD ANOTHER ONE (Y/N)','YN',ANEXT
            if ANEXT= 'Y'
               GOTO NOR
               @ 23,09 clear to 23,69
               RESTSCREEN(0,0,24,79,LAY)
               loop
            ELSE
               EXIT
            ENDIF
         enddo
      case option = 2
         go top
      case option = 8
         LAYAR=SAVESCREEN(0,0,24,79)
         choice = 'N'
         do get_optn with 'Delete (Y/N)','YN',choice
         if choice = 'Y'
            if rec_lock(0)
               delete
            endif
            unlock
            del_rec = 'Y'
            go bottom
         endif
         RESTSCREEN(0,0,24,79,LAYAR)
      case option = 3
         go bottom
      case option = 1
           LYYY=SAVESCREEN(0,0,24,79)
           SET INTEN ON
           COCOD=SPACE(4)
           compin=space(5)
           DO BOXE WITH 17,33,'Enter Initial of Company Name :','COMPIN','W+','RB','W+','N',5,.F.,.T.
           if lastkey()=27
              RESTSCREEN(0,0,24,79,LYYY)
              LOOP
*              return
           endif
           do CORP401.PRG
           KODE=COCOD
           SELE 1
           SET INDE TO &DR&F2
           SEEK KODE
           IF EOF()
               LAYAR=SAVESCREEN(0,0,24,79)
               set colo to W+/b,w+/B
               @ 23,09 clea to 23,69
               @ 23,10 SAY 'NOT EXIST'
               WAIT ' '
               RESTSCREEN(0,0,24,79,LYYY)
               GO BOTT
               loop
            endif
            RESTSCREEN(0,0,24,79,LORG)
*            EXIT
*         enddo
      case option = 6
            SET COLO TO BG+/B,W+/N
            @ 9,25 CLEAR TO 9,78
            LAY=SAVESCREEN(0,0,24,79)
            @ 09, 29 say "/"
            SET COLO TO GR+/N,W+/N
            @ 09, 25 PROMPT "YES"
            @ 09, 31 PROMPT "NO"
            rest from N:compan addi
            MENU TO CHCOM
            do case
               case CHCOM=1
                  codaea=codaea+1
                  KODE=STR(CODAEA,4)
                  AEAM=.T.
               case CHCOM=2
                  AEAM=.F.
                  CODCLI=CODCLI+1
                  KODE=STR(CODCLI,4)
            ENDCASE

            IF CHCOM=1
               SELE 5
               F5='MSHTYPE'
               SELE 5
               SET EXCLU OFF
               USE &DR&F5
               COUNT TO CNT
               IF CNT=0
                  RESTSCREEN(0,0,24,79,LAY)
                  LOOP
               ENDIF
               DECLARE FILD[CNT]
               DECLARE MCOD[CNT]
               DECLARE DARI[CNT]
               DECLARE HING[CNT]
               DECLARE MNAM[CNT]
               SELE 5
               GO TOP
               CR=0
               DO WHILE .NOT. EOF()
                  CR=CR+1
                  FILD[CR]=MEMB_CODE+' '+MEMB_NAME
                  MNAM[CR]=MEMB_NAME
                  MCOD[CR]=MEMB_CODE
                  DARI[CR]=MEMB_START
                  HING[CR]=MEMB_END
                  SKIP
               ENDDO
               set colo to w/b
               inkey()
               set colo to w+/rb,gr+/r
               @ 17,3 clea to 23,75
               @ 17,3 to 23,75 double
               pilih=achoice(18,5,22,73,FILD)
               IF LASTKEY()=13
                  DARF=FILD[PILIH]
                  CMEM=MCOD[PILIH]
                  NMEM=MNAM[PILIH]
                  MDR=DARI[PILIH]
                  MHG=HING[PILIH]
               else
                  SET COLO TO BG+/B,W+/N
                  RESTSCREEN(0,0,24,79,LAY)
                  SELE 1
                  LOOP
               ENDIF
            ENDIF

           SELE 1
            SET COLO TO w+/B,W+/N
            RESTSCREEN(0,0,24,79,LAY)
            @ 09,35 clea to 09,62
            @ 09,20 SAY AEAM
            @ 09,25 SAY NMEM

         SET DELI OFF
         SET INTE ON
         @ 12,20 GET name PICT '@!'
         @ 13,13 GET add1 PICT '@!'
         @ 14,13 GET add2 PICT '@!'
         @ 15,20 GET city PICT '@!'
         @ 16,20 GET negara pict '@!'
         @ 17,20 GET tel1 PICT '@!'
         @ 18,20 GET tel2 PICT '@!'
**
**  7/12/99 - Dickson 
**         @ 19,20 GET tel3 PICT '@!'
         @ 21,20 GET tel3 PICT '@!'
**

         @ 20,20 GET fax  pict '@!'
         @ 20,41 GET telex pict '@!'
         read
         LAYAR=SAVESCREEN(0,0,24,79)
         choice = 'Y'
         do get_optn with 'SAVE (Y/N)','YN',choice
         if choice = 'Y'
            if rec_lock()
               repl comp_name  with name,comp_tel1  with tel1,comp_tel2  with tel2
               repl comp_tel3  with tel3,comp_fax   with fax,comp_telex with telex
               repl comp_add1  with add1,comp_add2  with add2,comp_city  with city
               repl comp_count with negara
               IF CHCOM=1
                  REPL MEMB_CODE  WITH CMEM
                  REPL AEA_MEMBER WITH .T.
               else
                  REPL MEMB_CODE  WITH " "
                  REPL AEA_MEMBER WITH .F.
               ENDIF
            endif
            unlock
         endif
         @ 23,09 clear to 23,69
         RESTSCREEN(0,0,24,79,LAYAR)
      case option = 4
         skip
         if eof()
            go bottom
            LAYAR=SAVESCREEN(0,0,24,79)
            set colo to W+/b,w+/B
            @ 23,09 clea to 23,69
            @ 23,10 SAY 'LAST RECORD'
            WAIT ' '
            RESTSCREEN(0,0,24,79,LAYAR)
         endif
      case option = 5
         skip -1
         if bof()
            go top
            LAYAR=SAVESCREEN(0,0,24,79)
            set colo to W+/b,w+/B
            @ 23,09 clea to 23,69
            @ 23,10 SAY 'FIRST RECORD'
            WAIT ' '
            RESTSCREEN(0,0,24,79,LAYAR)
         endif
   endcase
enddo
if del_rec='Y'
   IF NET_USE("&DR&F2",.T.,'1',10)
      pack
   ENDIF
endif
close index
close data
set inte on
return
